package com.aiddea.maps;

import org.json.JSONException;
import org.json.JSONObject;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.OverlayItem;

public class GWI_Element extends OverlayItem {
	
	// Propietats del punt d'interes
	private String	title		= "";
	private String 	summary 	= "";
	private Double 	distance 	= 0.0;
	private int		rank 		= 0;
	private String  wikipediaUrl	= "";
	private int 	elevation	= 0;
	private String	countryCode = "";
	private Double	lng			= 0.0;
	private Double	lat 		= 0.0;
	private int		lngM		= 0;
	private int		latM 		= 0;
	private int		population  = 0;
	private String	lang		= "";
	private String	feature		= "";
	// ---
	private GeoPoint 	GPoint	= null;
	
	public GWI_Element(GeoPoint point, String title, String snippet, JSONObject Location)
	{
		// Passem d'aquests 3 paràmetres. Es sobreescriuran més endavant.
		super(point, title, snippet);
		
		try {
			
			// Assignem valors recuperats de l'objecte JSON Location
			if(Location.has("countryCode"))
				setCountryCode(Location.getString("countryCode"));
			
			if(Location.has("distance"))
				setDistance(Location.getDouble("distance"));
			
			if(Location.has("elevation"))
				setElevation(Location.getInt("elevation"));
			
			if(Location.has("feature"))
				setFeature(Location.getString("feature"));
			
			if(Location.has("lang"))
				setLang(Location.getString("lang"));
			
			if(Location.has("lat"))
				setLat(Location.getDouble("lat"));
				// El JSON ens torna Lat en doble i ha de ser int (*1000000)
				setLatM((int)((getLat() * 1E6)));
			
			if(Location.has("lng"))
				setLng(Location.getDouble("lng"));
				// El JSON ens torna Lon en doble i ha de ser int (*1000000)
				setLngM((int)((getLng() * 1E6)));
			
			if(Location.has("lng"))
				setLng(Location.getDouble("lng"));
			
			if(Location.has("population"))
				setPopulation(Location.getInt("population"));
			
			if(Location.has("rank"))
				setRank(Location.getInt("rank"));
			if(Location.has("summary"))
				setSummary(Location.getString("summary"));
			
			if(Location.has("title"))
				setTitle(Location.getString("title"));
			
			if(Location.has("wikipediaUrl"))
				setWikipediaUrl(Location.getString("wikipediaUrl"));
			
			setGPoint(new GeoPoint(getLatM(), getLngM()));
			
			// ** Sobreescribim les propietats heretades! **
			point = getGPoint();
			title = getTitle();
			snippet = getSummary();
			
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	private void setTitle(String title) {
		this.title = title;
	}

	public String getTitle() {
		return title;
	}

	private void setSummary(String summary) {
		this.summary = summary;
	}

	public String getSummary() {
		return summary;
	}

	private void setDistance(Double distance) {
		this.distance = distance;
	}

	public Double getDistance() {
		return distance;
	}

	private void setRank(int rank) {
		this.rank = rank;
	}

	public int getRank() {
		return rank;
	}

	private void setWikipediaUrl(String wikipediaUrl) {
		this.wikipediaUrl = wikipediaUrl;
	}

	public String getWikipediaUrl() {
		return wikipediaUrl;
	}

	private void setElevation(int elevation) {
		this.elevation = elevation;
	}

	public int getElevation() {
		return elevation;
	}

	private void setCountryCode(String countryCode) {
		this.countryCode = countryCode;
	}

	public String getCountryCode() {
		return countryCode;
	}

	private void setLng(Double lng) {
		this.lng = lng;
	}

	public Double getLng() {
		return lng;
	}

	private void setLat(Double lat) {
		this.lat = lat;
	}

	public Double getLat() {
		return lat;
	}

	private void setPopulation(int population) {
		this.population = population;
	}

	public int getPopulation() {
		return population;
	}

	private void setLang(String lang) {
		this.lang = lang;
	}

	public String getLang() {
		return lang;
	}

	private void setFeature(String feature) {
		this.feature = feature;
	}

	public String getFeature() {
		return feature;
	}

	private void setGPoint(GeoPoint gPoint) {
		GPoint = gPoint;
	}

	private GeoPoint getGPoint() {
		return GPoint;
	}
		
	public OverlayItem getOvItem() {
		return new OverlayItem(getGPoint(), getTitle(), getSnippet());
	}
	
	private void setLngM(int lngM) {
		this.lngM = lngM;
	}

	public int getLngM() {
		return lngM;
	}

	private void setLatM(int latM) {
		this.latM = latM;
	}

	public int getLatM() {
		return latM;
	}
	
}
